// pages/doctorInr/doctorInr.js
import { getDoctorDetail, login, formatDate} from '../../utils/api.js';
var WxParse = require('../../wxParse/wxParse.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLogin: false,
    currentDate:'',
    doctorInfo:{},
    content:''
  },
  register(e) {
    if (this.data.isLogin) {
      wx.navigateTo({
        url: '/pages/appointment/appointment?id=' + e.currentTarget.dataset.id + '&date=' + this.data.currentDate,
      })
    } else {
      login(false, '/pages/appointment/appointment?id=' + e.currentTarget.dataset.id + '&date=' + this.data.currentDate)
    }

  },
  getsph(e) {
    let video_id = this.data.doctorInfo.video_id
    let videoId = wx.getStorageSync('videoId')
    wx.openChannelsActivity({
      finderUserName: videoId,
      feedId: video_id,
      success: (res) => {
        console.log(res)
      },
      fail: (err) => {
        console.log(err)
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let date = options.date ? options.date : formatDate(new Date())
    let id = options.id
    getDoctorDetail({ id: id, date: date}).then(res=>{
      wx.setNavigationBarTitle({
        title: res.data.name
      })
      var article = res.data.content;//article是取到的数据 
      var that = this;
      WxParse.wxParse('article', 'html', article, that, 5);
      this.setData({
        doctorInfo:res.data,
        // content: res.data.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto"').replace(/\img>/gi, 'img>').replace(/\<figure class="image">/gi, '').replace(/\<\/figure>/gi, ''),
        currentDate: date
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (wx.getStorageSync('isLogin')) {
      this.setData({
        isLogin: wx.getStorageSync('isLogin')
      })
    } else {
      this.setData({
        isLogin: false
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})